/**
 * Created by kenz on 2017/7/3.
 */
export function trim(str) {
  return str.replace(/(^\s*)|(\s*$)/g, "");
}


export function getDateDiff(dateTimeStamp){
  //now = 1000 * parseInt(now);
  dateTimeStamp = 1000 * parseInt(dateTimeStamp);
  var minute = 1000 * 60;
  var hour = minute * 60;
  var day = hour * 24;
  var halfamonth = day * 15;
  var month = day * 30;
  //var diffValue = now - dateTimeStamp;
  var diffValue = dateTimeStamp;
  if(diffValue < 0){

  }
  var monthC =diffValue/month;
  var weekC =diffValue/(7*day);
  var dayC =diffValue/day;
  var hourC =diffValue/hour;
  var minC =diffValue/minute;
  var result = '';
  if(monthC>=1){
    result=parseInt(monthC) + "个月前";
  }
  else if(weekC>=1){
    result=parseInt(weekC) + "周前";
  }
  else if(dayC>=1){
    result=parseInt(dayC) +"天前";
  }
  else if(hourC>=1){
    result=parseInt(hourC) +"个小时前";
  }
  else if(minC>=1){
    result=parseInt(minC) +"分钟前";
  }else {
    result="刚刚";
  }

  return result;
}

export function get_time_format(timestamp){
  if(timestamp){
    var date = new Date(parseInt(timestamp) * 1000);
  }else{
    var date = new Date();
  }
  var Y = date.getFullYear(),
    m = date.getMonth()+1,
    d = date.getDate(),
    H = date.getHours(),
    i = date.getMinutes(),
    s = date.getSeconds();
  if(m<10){
    m = '0'+m;
  }
  if(d<10){
    d = '0'+d;
  }
  if(H<10){
    H = '0'+H;
  }
  if(i<10){
    i = '0'+i;
  }
  if(s<10){
    s = '0'+s;
  }
  var t = Y+'-'+m+'-'+d+' '+H+':'+i;
  return t;
}
